<template>
  <div>
    <search-condition @search="onSearch" @reset="onReset" :showOther="true"/>
    <el-card>
      <div class="clearfix" style="margin-bottom:16px" v-show="professionalAuditStandards && professionalAuditStandards.length">
        <div class="edu-page-title mg-bottom">
          <span>{{$t("auditStandard.creditStandard")}}</span>
        </div>
        <!-- 专业审核标准-->
        <professional-audit-standards ref="professional" :isSetting="true" />
        <div class="float-right" style="margin-top: 16px;">
          <el-button @click="onCancel">{{$t("message.cancel")}}</el-button>
          <el-button @click="onSubmit" type="primary">{{$t("message.confirm")}}</el-button>
        </div>
      </div>
    </el-card>
  </div>
</template>
<script>
  import api from 'common/src/api/preparatoryGraduation/auditStandards';
  export default {
    name: 'setProfessionalAuditStandardsTab',
    components: {
      searchCondition: () => import('./searchCondition'),
      professionalAuditStandards: () =>  import('./professionalAuditStandards')
    },
    data() {
      return {
        professionalAuditStandards: [],
        originalData: {},
        queryForm: {}
      };
    },
    methods: {
      onSearch(condition) {
        api.query(condition).then(res => {
          this.queryForm = condition;
          const data = res && res.data;
          this.professionalAuditStandards = data.professionalAuditStandards;
          if (!this.professionalAuditStandards || !this.professionalAuditStandards.length) {
            this.$message({
              type: 'warning',
              message: '无符合条件数据'
            });
            return;
          }
          this.initTableContent();
        });
      },
      onReset() {
        this.professionalAuditStandards = [];
        this.initTableContent();
      },
      onCancel() {
       this.onSearch(this.queryForm);
      },
      onSubmit() {
        const ref = this.$refs['professional'];
        const params = {
         ...this.queryForm,
         list: ref.getProfessionalAuditStandards()
        };
        api.professionalSetting(params).then(() => {
          this.$message({
            type: 'success',
            message: '操作成功！'
          });
        });
      },
      initTableContent() {
        this.$refs['professional'].init(this.professionalAuditStandards);
      }
    }
  };
</script>
<style lang="scss" scoped>
  .mg-bottom{
    margin-bottom: 15px;
  }
  .edu-page-title {
    span {
      line-height: 24px;
      display: inline-block;
      padding-right: 10px;
      font-size: 18px;
      font-weight: bold;
      color: #2b3b4e;
    }
  }
</style>
